﻿using System;
using System.Windows;
using Infrastructure;
using Presentation;
using Application;

namespace WpfClient
{
    public partial class WpfView : Window, ITriangleView
    {
        #region Implementation of interface ITriangleView

        public string PointA { get { return textBoxA.Text; } }
        public string PointB { get { return textBoxB.Text; } }
        public string PointC { get { return textBoxC.Text; } }

        public string AB { set; get; }
        public string BC { set; get; }
        public string CA { set; get; }

        public string Alpha { set; get; }
        public string Beta  { set; get; }
        public string Gamma { set; get; }

        public string Perimeter { set; get; }
        public string Square    { set; get; }

        public string ErrorMessage { set; get; }
        
        public event EventHandler<EventArgs> CalculateParameters;
        public event TrianglePresenter.LogEventHandler WriteToLog;

        #endregion

        private TxtLogger logTxt;
        private HtmlLogger logHtml;
        private ILogger currentLog;
       
        public WpfView()
        {      
           TriangleApplication.Start(this);
           InitializeComponent();
           logTxt = new TxtLogger();
           logHtml = new HtmlLogger();
           currentLog = logTxt;
        }

        private void CalculateButtonClick(object sender, RoutedEventArgs e)
        {
            CalculateParameters(sender, e);

            textBoxPerimeter.Text = Perimeter;
            textBoxSquare.Text = Square;
            textBoxAB.Text = AB;
            textBoxBC.Text = BC;
            textBoxCA.Text = CA;
            textBoxBAC.Text = Alpha;
            textBoxCBA.Text = Beta;
            textBoxACB.Text = Gamma;

            labelErrorMessage.Content = ErrorMessage;

            WriteToLog(logTxt);
            WriteToLog(logHtml);
        }

        private void ViewLogButtonClick(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(currentLog.Name);
        }

        private void RadioButtonTxtCheckedChanged(object sender, RoutedEventArgs e)
        {
            currentLog = logTxt;
        }

        private void RadioButtonHtmlCheckedChanged(object sender, RoutedEventArgs e)
        {
            currentLog = logHtml;
        }
    }
}
